// #include "room.hpp"
// #include "session.hpp"
// #include "matcher.hpp"
#include "server.hpp"
#include <sstream>
#include <vector>

#define HOST "127.0.0.1"
#define PORT 3306
#define USER "root"
#define PASSWD "15236331345"
#define DBNAME "gobang"

void mysql_test()
{
    MYSQL *mysql = mysql_util::mysql_create(HOST, USER, PASSWD, DBNAME, PORT);
    std::string sql = "insert stu values(null,'你好',10,100,100,100);";
    bool ret = mysql_util::mysql_exec(mysql, sql);
    if (!ret)
        return;
    mysql_util::mysql_destory(mysql);
}
void json_test()
{
    // 序列化
    Json::Value stu;
    stu["name"] = "zhangsan";
    stu["age"] = 19;
    stu["socre"].append(77.5);
    stu["socre"].append(88);
    stu["socre"].append(99.5);
    std::string str;
    json_util::Serialize(stu, str);
    DBG_LOG("%s", str.c_str());
    // 反序列化
    Json::Value root;
    json_util::UnSerialize(str, root);
    std::cout << "反序列化结果:\n"
              << "name:" << root["name"].asString() << "\n"
              << "age:" << root["age"].asInt() << "\n"
              << "socre:" << root["socre"][0].asFloat() << " " << root["socre"][1].asFloat()
              << " " << root["socre"][2].asFloat() << "\n";
}

void str_test()
{
    std::string src = ",,123,.456,,,78.9,,,";
    std::vector<std::string> ret;
    string_util::split(src,",",ret);
    for(int i = 0;i<ret.size();i++)
    {
        std::cout<<ret[i]<<std::endl;
    }
}

void file_test()
{
    std::string body;
    file_util::read("./makefile",body);
    std::cout << body << std::endl;
}

void db_test()
{
    user_table ut(HOST,USER,PASSWD,DBNAME,PORT);
    Json::Value user;
    user["username"] = "7";
    //user["password"] = "123123456";
    ut.insert(user);

    // bool ret = ut.login(user);
    // if(!ret)
    // {
    //     DBG_LOG("login fail");
    // }
    // bool ret = ut.select_by_name("xiaoming",user);
    // std::string body;
    // json_util::Serialize(user,body);
    // std::cout << body;
    // bool ret = ut.lose(1);
    // std::string body;
    // json_util::Serialize(user,body);
    // std::cout << body;
}

void online_test()
{
    online_manager oh;
    wsserver_t::connection_ptr conn;
    uint64_t uid = 2;
    oh.enter_game_hall(2,conn);
    if(oh.is_in_game_hall(uid))
    {
        DBG_LOG("有的兄弟");
    }
    else
    {
        DBG_LOG("没有");
    }

    oh.exit_game_hall(2);
    if(oh.is_in_game_room(uid))
    {
        DBG_LOG("有的兄弟");
    }
    else
    {
        DBG_LOG("没有");
    }
}

int main()
{
    // json_test();
    // str_test();
    // file_test();
    // db_test();
    // online_test();
    // user_table ut(HOST,USER,PASSWD,DBNAME,PORT);
    // online_manager om;
    // // room r(10,&ut,&oh);
    // room_manager rm(&ut,&om);
    // room_ptr rp = rm.create_room(10,20);
    // matcher mc(&rm,&ut,&om);
    gobang_server _server(HOST,USER,PASSWD,DBNAME,PORT);
    _server.start(8081);

    return 0;
}